package com.itheima.ydd.controller;

import com.itheima.ydd.common.R;
import com.itheima.ydd.dto.AdvimgDto;
import com.itheima.ydd.dto.PageInfo;
import com.itheima.ydd.pojo.YddAdvimg;
import com.itheima.ydd.service.YddAdvimgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("ydd_advimg")
public class YddAdvimgController {
    @Autowired
    private YddAdvimgService yddAdvimgService;


    /**
     * 根据id查询广告图详情,地址等等
     * @param id
     * @return
     */
    @GetMapping("rowInfo")
    public ResponseEntity<R<YddAdvimg>> getAdvImgById(Integer id){
        return yddAdvimgService.getAdvById(id);
    }



    /**
     * 广告图列表分页查询
     * @param
     * @return
     */
    @GetMapping("list")
    public ResponseEntity<R<PageInfo<AdvimgDto>>> listAdvImg(String advimgdesc, String advimgpos, Integer page, Integer limit){

        return yddAdvimgService.listByPagesWithPosName(advimgdesc,advimgpos,page,limit);
    }


    @PostMapping("update")
    public ResponseEntity<R<String>> updateAdimg(@RequestBody YddAdvimg yddAdvimg){
        return yddAdvimgService.updateImg(yddAdvimg);
    }

    @GetMapping("del")
    public ResponseEntity<R<String>> deleteAdimg(Integer id){
        yddAdvimgService.removeById(id);
        return ResponseEntity.ok(R.success("删除成功"));
    }

    //GET /ydd_advimg/add
    @PostMapping("add")
    public ResponseEntity<R<String>> addAdimg(@RequestBody YddAdvimg yddAdvimg){
        yddAdvimgService.save(yddAdvimg);
        return ResponseEntity.ok(R.success("新增成功"));
    }

}
